import requests
#cron: 40 21 * * *
#new Env("老奥")
url = "http://api.bjjfnet.com/data/opencode/2032"
webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c4ed66c7-ea68-4b51-be3f-8319beb4504d"

headers = {
  'Accept-Language': "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
}

response = requests.get(url, headers=headers)
data = response.json()

if 'data' in data:
    message = "「老澳门」\n\n"  # 添加头部信息
    for item in data['data'][:5]:  # 取前五条数据
        message +=f'{"期数":<10}:{item["issue"]}\n'
        message +=f'{"开奖号码":<10}:{item["openCode"]}\n'
        message +=f'{"开奖时间":<10}:{item["openTime"]}\n\n'

    payload = {
        "msgtype": "text",
        "text": {
            "content": message
        }
    }

    response = requests.post(webhook_url, json=payload)
    if response.status_code == 200:
        print("通知已成功发送.")
    else:
        print("通知发送失败.")
else:
    print("在响应中没有找到数据.")
